home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE2 / PD / VINCE / !ViNCe / c / display < prev    next >
Text File  |  2002-07-03  |  2KB  |  118 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "display.h"
  6. #include "vncviewer.h"
  7. #include "mcode.h"
  8.  
  9.  
  10. static int bbox[4];
  11. static int validbbox = 0;
  12.  
  13.  
  14. void display_copy(int rx, int ry, int rw, int rh, int sx, int sy) {
  15.  
  16.   unsigned short *from, *to;
  17.   int y;
  18.  
  19.   from = display.data + display.shortsperline*sy + sx;
  20.   to = display.data + display.shortsperline*ry + rx;
  21.  
  22.   if (from > to) {
  23.     for (y = 0; y < rh; y++) {
  24.       memcpy(to, from, 2*rw);
  25.       to += display.shortsperline;
  26.       from += display.shortsperline;
  27.     }
  28.   } else {
  29.     to += display.shortsperline*(rh-1);
  30.     from += display.shortsperline*(rh-1);
  31.     for (y = 0; y < rh; y++) {
  32.       memcpy(to, from, 2*rw);
  33.       to -= display.shortsperline;
  34.       from -= display.shortsperline;
  35.     }
  36.   }
  37. }
  38.  
  39.  
  40. void display_raw(int rx, int ry, int rw, int rh, void *buf, int dithered8) {
  41.  
  42.   unsigned short *out;
  43.   int y, x;
  44.  
  45.   out = display.data + display.shortsperline*ry + rx;
  46.  
  47.   if ((dithered8) || (bpp == 8)) {
  48.     char *in;
  49.  
  50.     in = buf;
  51.     for (y = 0; y < rh; y++) {
  52.       for (x = 0; x < rw; x++)     out[x] = rgb332_rgb555_table[in[x]];
  53.       out += display.shortsperline;
  54.       in += rw;
  55.     }
  56.  
  57.   } else {
  58.     unsigned short *in;
  59.  
  60.     in = buf;
  61.     for (y = 0; y < rh; y++) {
  62.       memcpy(out, in, 2*rw);
  63.       out += display.shortsperline;
  64.       in += rw;
  65.     }
  66.   }
  67. }
  68.  
  69.  
  70. void display_fillrectangle(int rx, int ry, int rw, int rh, unsigned short pix) {
  71.  
  72.   unsigned short *out;
  73.  
  74.   out = display.data + display.shortsperline*ry + rx;
  75.   if (bpp == 8) {
  76.     mc_fill_rectangle(out, rw, rh, display.shortsperline, pix);
  77.   } else {
  78.     mc_fill_rectangle(out, rw, rh, display.shortsperline, pix);
  79.   }
  80. }
  81.  
  82.  
  83.  
  84. void display_flush() {
  85.  
  86.   if (!validbbox)   return;
  87.   UpdateWindow(bbox[0], bbox[1], bbox[2]-bbox[0], bbox[3]-bbox[1]);
  88.   validbbox = 0;
  89. }
  90.  
  91.  
  92. void display_add_rectangle(int x, int y, int w, int h) {
  93.  
  94.   if (validbbox) {
  95.     unsigned int s;
  96.     int x0, y0, x1, y1;
  97.  
  98.     s = (unsigned int) (bbox[2]-bbox[0]) * (bbox[3]-bbox[1]) + w * h;
  99.     x0 = x   < bbox[0] ? x   : bbox[0];
  100.     y0 = y   < bbox[1] ? y   : bbox[1];
  101.     x1 = x+w > bbox[2] ? x+w : bbox[2];
  102.     y1 = y+h > bbox[3] ? y+h : bbox[3];
  103.     if (((x1 - x0) * (y1 - y0)) >> addrectshift <= s) {
  104.       bbox[0] = x0;
  105.       bbox[1] = y0;
  106.       bbox[2] = x1;
  107.       bbox[3] = y1;
  108.       return;
  109.     }
  110.     display_flush();
  111.   }
  112.   bbox[0] = x;
  113.   bbox[1] = y;
  114.   bbox[2] = x+w;
  115.   bbox[3] = y+h;
  116.   validbbox = 1;
  117. }
  118.